axios.interceptors.response.use(function (response) { let {status,message} = response.data;
  if (status === 1) layer.msg(message); 
    // 对响应数据做点什么
    return response;
  }, function (error) {
      let {status,message} = error.response.data;
    //   layer.msg('输入用户名太长');
      layer.msg(message);
    // 对响应错误做点什么
      return Promise.reject(error);
  });
$('.login a').click(function () {
    $('.register').show();
});

$('.register a').click(function () {
    $('.register').hide();
});
$('.login form').on('submit',function(e) {
    e.preventDefault();
    let data = $(this).serialize();
    axios.post('http://www.itcbc.com:8080/api/login',data).then(res => {
        let {status,message,token} = res.data;
        // if (status ===0 ) {
        //     localStorage.setItem('token',token)
        //     layer.msg(message,{time: 1500},() => {
        //         location.href = './demo.html'
        //     })
        // }
        if (status ===0 ) {
            localStorage.setItem('token',token);
            location.href = './index.html'
        }
    })
});
$('.register form').on('submit',function(e) {
    e.preventDefault();
    let data = $(this).serialize();
    axios.post('http://www.itcbc.com:8080/api/reguser',data).then(res => {
        let {status ,message} = res.data;
        if(status === 0) {
            layer.msg(message);
            $('.register form')[0].reset();
            $('.register').hide();
        }
    })
})
let form = layui.form;
form.verify({
    len:[
        /^[\S]{6,12}$/
        ,'密码必须6到12位，且不能出现空格'
      ],
    same: function(val) {
        let pwd = $('.pwd').val();
        if (val !== pwd ) return '输入密码不一致'
    }
})
